<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="证件类型" prop="documentType2">-->
<!--        <el-input-->
<!--          v-model="queryParams.documentType2"-->
<!--          placeholder="请输入证件类型"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="用户" prop="zxsname">
        <el-input
          v-model="queryParams.zxsname"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.zxs_check_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['business:application:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['business:application:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:application:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['business:application:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="applicationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键ID" align="center" prop="id" />-->
      <el-table-column label="用户" align="center" prop="zxsname" />
<!--      <el-table-column label="证件类型" align="center" prop="documentType2" />-->
<!--      <el-table-column label="真实姓名" align="center" prop="realName2" />-->
<!--      <el-table-column label="证件号码" align="center" prop="documentNumber2" />-->
      <el-table-column label="内容类型" align="center" prop="contentType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.check_content_type" :value="scope.row.contentType"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxs_check_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="审核拒绝原因" align="center" prop="auditReason" />
      <el-table-column label="提交时间" align="center" prop="createTime" width="180" />


<!--      <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.status =='0'"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="viewhandleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:application:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改咨询师入驻申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
<!--        <el-form-item label="用户ID" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入用户ID" />-->
<!--        </el-form-item>-->
        <el-divider content-position="left">基本信息</el-divider>
        <el-form-item label="姓名" prop="zxsname"  >
          <el-input v-model="form.zxsname" placeholder="姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="userphone"  >
          <el-input v-model="form.userphone" placeholder="手机号" />
        </el-form-item>
        <el-form-item label="身份证号" prop="useridcard"  >
          <el-input v-model="form.useridcard" placeholder="身份证号" />
        </el-form-item>
        <el-form-item label="照片" prop="profilePhotoUrl"  >
          <image-upload v-model="form.profilePhotoUrl"  />
        </el-form-item>
        <el-divider content-position="left">审核信息</el-divider>
        <el-form-item label="内容类型" prop="contentType"  disabled>
          <el-select v-model="form.contentType"  disabled placeholder="请选择内容类型">
            <el-option
              v-for="dict in dict.type.check_content_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="职业照片或视频" prop="professionalPhoto1"  v-if="form.contentType =='1'">
          <image-upload v-model="form.professionalPhoto1"  />
        </el-form-item>
        <el-form-item label="证件类型" prop="documentType2" v-if="form.contentType =='2' ">
          <el-input v-model="form.documentType2" placeholder="请输入证件类型" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName2"     v-if="form.contentType =='2'" >
          <el-input v-model="form.realName2" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="证件号码" prop="documentNumber2" v-if="form.contentType =='2'">
          <el-input v-model="form.documentNumber2" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="证件照片" prop="documentPhotos2" v-if="form.contentType =='2'" >
          <image-upload v-model="form.documentPhotos2" />
        </el-form-item>
        <el-form-item label="证书名称" prop="certificateName3" v-if="form.contentType =='3'" >
          <el-input v-model="form.certificateName3" placeholder="请输入证书名称" />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNumber3"  v-if="form.contentType =='3'">
          <el-input v-model="form.certificateNumber3" placeholder="请输入证书编号" />
        </el-form-item>
        <el-form-item label="证书发证日期" prop="certificateIssuanceDate3"  v-if="form.contentType =='3'">
          <el-date-picker clearable size="small"
            v-model="form.certificateIssuanceDate3"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择证书发证日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="证书照片" prop="certificatePhotos3"  v-if="form.contentType =='3'">
          <image-upload v-model="form.certificatePhotos3" />
        </el-form-item>
        <el-form-item label="擅长领域" prop="expertiseField4"  v-if="form.contentType =='4'">
          <el-input v-model="form.expertiseField4" placeholder="请输入擅长领域" />
        </el-form-item>
        <el-form-item label="擅长群体" prop="expertiseGroup5" v-if="form.contentType =='5'">
          <el-input v-model="form.expertiseGroup5" placeholder="请输入擅长群体" />
        </el-form-item>
        <el-form-item label="流派取向" prop="orientation6" v-if="form.contentType =='6'">
          <el-input v-model="form.orientation6" placeholder="请输入流派取向" />
        </el-form-item>
        <el-form-item label="发证单位" prop="trainingOrganization7"  v-if="form.contentType =='7'">
          <el-input v-model="form.trainingOrganization7" placeholder="请输入发证单位" />
        </el-form-item>
        <el-form-item label="培训项目" prop="trainingProject7" v-if="form.contentType =='7'">
          <el-input v-model="form.trainingProject7" placeholder="请输入培训项目" />
        </el-form-item>
        <el-form-item label="培训时长" prop="trainingDuration7" v-if="form.contentType =='7'">
          <el-input v-model="form.trainingDuration7" placeholder="请输入培训时长" />
        </el-form-item>
        <el-form-item label="证书名称" prop="trainingCertificateName7" v-if="form.contentType =='7'">
          <el-input v-model="form.trainingCertificateName7" placeholder="请输入证书名称" />
        </el-form-item>
        <el-form-item label="证件号码" prop="trainingCertificateNumber7" v-if="form.contentType =='7'">
          <el-input v-model="form.trainingCertificateNumber7" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="颁证时间" prop="trainingCertificationDate7" v-if="form.contentType =='7'">
          <el-date-picker clearable size="small"
            v-model="form.trainingCertificationDate7"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择颁证时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="培训证书照片" prop="trainingPhotos7" v-if="form.contentType =='7'">
          <image-upload v-model="form.trainingPhotos7" />
        </el-form-item>
        <el-form-item label="证明单位" prop="consultationOrganization8" v-if="form.contentType =='8'">
          <el-input v-model="form.consultationOrganization8" placeholder="请输入证明单位" />
        </el-form-item>
        <el-form-item label="咨询项目" prop="consultationProject8" v-if="form.contentType =='8'">
          <el-input v-model="form.consultationProject8" placeholder="请输入咨询项目" />
        </el-form-item>
        <el-form-item label="咨询开始时间" prop="consultationStartDate8" v-if="form.contentType =='8'">
          <el-date-picker clearable size="small"
            v-model="form.consultationStartDate8"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择咨询时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="咨询结束时间" prop="consultationEndDate8" v-if="form.contentType =='8'">
          <el-date-picker clearable size="small"
                          v-model="form.consultationEndDate8"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择咨询时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="咨询时长" prop="consultationDuration8" v-if="form.contentType =='8'">
          <el-input v-model="form.consultationDuration8" placeholder="请输入咨询时长" />
        </el-form-item>
        <el-form-item label="上传的咨询相关图片URL字符串" prop="consultationPhotos8" v-if="form.contentType =='8'">
          <el-input v-model="form.consultationPhotos8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="证明单位" prop="supervisionOrganization9"  v-if="form.contentType =='9'" >
          <el-input v-model="form.supervisionOrganization9" placeholder="请输入证明单位" />
        </el-form-item>
        <el-form-item label="督导姓名" prop="supervisorName9"  v-if="form.contentType =='9'">
          <el-input v-model="form.supervisorName9" placeholder="请输入督导姓名" />
        </el-form-item>
        <el-form-item label="督导时间" prop="supervisionStartDate9" v-if="form.contentType =='9'">
          <el-date-picker clearable size="small"
            v-model="form.supervisionStartDate9"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择督导时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导时长" prop="supervisionDuration9" v-if="form.contentType =='9'">
          <el-input v-model="form.supervisionDuration9" placeholder="请输入督导时长" />
        </el-form-item>
        <el-form-item label="上传的督导相关图片URL字符串" prop="supervisionPhotos9" v-if="form.contentType =='9'" >
          <image-upload v-model="form.supervisionPhotos9" />
        </el-form-item>
        <el-form-item label="审核状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.zxs_check_status"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核拒绝原因" prop="auditReason">
          <el-input v-model="form.auditReason"   type="textarea"   placeholder="请输入审核拒绝原因" />
        </el-form-item>
        <el-form-item label="身份" prop="sf" v-if="title =='审核咨询师入驻申请'">
          <el-select v-model="form.sf" placeholder="请选择身份" clearable size="small">
            <el-option
              v-for="dict in dict.type.zxs_sf"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary"  v-if="title =='审核咨询师入驻申请'" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApplication, getApplication, delApplication, addApplication, updateApplication } from "@/api/business/application";

export default {
  name: "Application",
  dicts: ['zxs_check_status','check_content_type','zxs_sf'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询师入驻申请表格数据
      applicationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        professionalPhoto1: null,
        documentType2: null,
        realName2: null,
        documentNumber2: null,
        documentPhotos2: null,
        certificateName3: null,
        certificateNumber3: null,
        certificateIssuanceDate3: null,
        certificatePhotos3: null,
        expertiseField4: null,
        expertiseGroup5: null,
        orientation6: null,
        trainingOrganization7: null,
        trainingProject7: null,
        trainingDuration7: null,
        trainingCertificateName7: null,
        trainingCertificateNumber7: null,
        trainingCertificationDate7: null,
        trainingPhotos7: null,
        consultationOrganization8: null,
        consultationProject8: null,
        consultationStartDate8: null,
        consultationDuration8: null,
        consultationPhotos8: null,
        supervisionOrganization9: null,
        supervisorName9: null,
        supervisionStartDate9: null,
        supervisionDuration9: null,
        supervisionPhotos9: null,
        contentType: null,
        status: null,
        auditReason: null,
        createdAt: null,
        updatedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        contentType: [
          { required: true, message: "内容类型不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询咨询师入驻申请列表 */
    getList() {
      this.loading = true;
      listApplication(this.queryParams).then(response => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        professionalPhoto1: null,
        documentType2: null,
        realName2: null,
        documentNumber2: null,
        documentPhotos2: null,
        certificateName3: null,
        certificateNumber3: null,
        certificateIssuanceDate3: null,
        certificatePhotos3: null,
        expertiseField4: null,
        expertiseGroup5: null,
        orientation6: null,
        trainingOrganization7: null,
        trainingProject7: null,
        trainingDuration7: null,
        trainingCertificateName7: null,
        trainingCertificateNumber7: null,
        trainingCertificationDate7: null,
        trainingPhotos7: null,
        consultationOrganization8: null,
        consultationProject8: null,
        consultationStartDate8: null,
        consultationDuration8: null,
        consultationPhotos8: null,
        supervisionOrganization9: null,
        supervisorName9: null,
        supervisionStartDate9: null,
        supervisionDuration9: null,
        supervisionPhotos9: null,
        contentType: null,
        status: 0,
        auditReason: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加咨询师入驻申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApplication(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审核咨询师入驻申请";
        this.form.status = 1;
      });
    },

    viewhandleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApplication(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看咨询师入驻申请";
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApplication(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplication(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除咨询师入驻申请编号为"' + ids + '"的数据项？').then(function() {
        return delApplication(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/application/export', {
        ...this.queryParams
      }, `application_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
